<?php
/**
 * Created by PhpStorm.
 * User: zhaoye
 * Date: 16/7/15
 * Time: 下午3:58
 */

namespace controller\Api;

use model\Group;
use ZPHP\Core\Db;
use tool\M2Result;
use tool\Validation;
use ZPHP\Core\Log;

class CRoom extends Base{

    public function init()
    {
        return parent::init();
    }

    /**
     * 创建一个群组
     * @return string
     */
    public function createRoom()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->createGroup($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }
    /**
     * 修改群组信息
     * @return string
     */
    public function modifyRoomInfo()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->modifyGroupInfo($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 获取一个或多个群组的详情
     * @return string
     */
    public function getRoomDetail()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->getGroupDetail($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 删除群组
     * @return string
     */
    public function deleteRoom()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->deleteGroup($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 获取所有群组
     * @return string
     */
    public function getRooms()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->getGroups($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 获取群组中的成员
     * @return string
     */
    public function getRoomUsers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->getGroupUsers($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 群组单个加人
     * @return string
     */
    public function addRoomMember()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->addGroupMember($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 群组批量加人
     * @return string
     */
    public function addRoomMembers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->addGroupMembers($params,'room');
        if($data !== true)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $m2_result->errordata = $data;

        }
        return $m2_result->toJson();
    }

    /**
     * 群组单个减人
     * @return string
     */
    public function deleteRoomMember()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->deleteGroupMember($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 群组批量减人
     * @return string
     */
    public function deleteRoomMembers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->deleteGroupMembers($params,'room');
        if($data !== true)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $m2_result->errordata = $data;

        }
        return $m2_result->toJson();
    }

    /**
     * 获取一个用户参与的所有群组
     * @return string
     */
    public function getRoomsForUser()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->getGroupsForUser($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 群组转让
     * @return string
     */
    public function changeRoomOwner()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->changeGroupOwner($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }


    /**
     * 群组黑名单单个加人
     * @return string
     */
    public function addRoomBlackMember()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->addGroupBlackMember($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 群组批量加人
     * @return string
     */
    public function addRoomBlackMembers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->addGroupBlackMembers($params,'room');
        if($data !== true)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $m2_result->errordata = $data;

        }
        return $m2_result->toJson();
    }

    /**
     * 群组黑名单单个减人
     * @return string
     */
    public function deleteRoomBlackMember()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->deleteGroupBlackMember($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 群组黑名单批量减人
     * @return string
     */
    public function deleteRoomBlackMembers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->deleteGroupBlackMembers($params,'room');
        if($data !== true)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $m2_result->errordata = $data;

        }
        return $m2_result->toJson();
    }


    /**
     * 查询一个群组黑名单用户名列表
     * @return string
     */
    public function getRoomBlackList()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Group();
        $data = yield $model->getGroupBlackList($params,'room');
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

}
